package com.sls.api.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.sls.api.game.constant.Constant;
import com.sls.api.game.constant.ExCodeDes;
import com.sls.api.game.pojo.AreaServer;
import com.sls.api.game.pojo.Bill;
import com.sls.api.game.pojo.CardInfo;
import com.sls.api.game.pojo.ChargeTypeInfo;
import com.sls.api.game.pojo.Goods;
import com.sls.api.game.pojo.GoodsBrand;
import com.sls.api.game.pojo.GoodsTransactionInfo;
import com.sls.api.game.pojo.OrderInfo;
import com.sls.api.game.pojo.UserBalanceInfo;

/**
 * 组织返回的xml数据
 * 
 * @author cx
 * 
 */
public class OrganizeRespXmlData {

	private static String xmlData;

	/**
	 * 组织品牌同步的返回xml数据
	 * 
	 * @param resCode
	 *            响应状态码
	 * @param resReasonMsg
	 *            响应信息
	 * @param brands
	 *            品牌列表
	 * @return
	 */
	public static String assembleXmlForBrandSync(String resCode,
			String resReasonMsg, List<GoodsBrand> brands) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {
			if (brands != null && brands.size() > 0 && brands.get(0) != null) {
				GoodsBrand b = brands.get(0);
				assembleSuccessXml(builder, b.getFailedCode(),
						b.getFailedReason(), "SUCCESS");
				for (GoodsBrand brand : brands) {
					String gameName = brand.getGameName();
					String brandId = brand.getGoodsCategoryId();
					String remark = brand.getRemark();
					builder.append("<brand>");
					builder.append("<brandId>");
					if (StringUtils.isNotEmpty(brandId)) {
						builder.append(brandId);
					}
					builder.append("</brandId>");
					builder.append("<brandName>");
					if (StringUtils.isNotEmpty(gameName)) {
						gameName = StringFilter.filterAngleBrackets(gameName);
						builder.append(gameName);
					}
					builder.append("</brandName>");
					builder.append("<remark>");
					if (StringUtils.isNotEmpty(remark)) {
						remark = StringFilter.filterAngleBrackets(remark);
						builder.append(remark);
					}
					builder.append("</remark>");
					builder.append("</brand>");
				}
			}
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 合作用户查询余额返回的数据
	 * 
	 * @param resCode
	 * @param resMsg
	 * @param balance
	 * @return
	 */
	public static String assembleXmlForUserBalance(String resCode,
			String resReasonMsg, UserBalanceInfo balance) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {
			assembleSuccessXml(builder, balance.getFailedCode(),
					balance.getFailedReason(), balance.getResMsg());
			if (balance != null) {
				builder.append("<balance>");
				if (StringUtils.isNotEmpty(balance.getBalance())) {
					builder.append(balance.getBalance());
				}
				builder.append("</balance>");
			}
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 交易返回信息
	 * 
	 * @param resCode
	 * @param resReasonMsg
	 * @param goodsTransaction
	 * @return
	 */
	public static String assembleXmlForGoodsTransaction(String resCode,
			String resReasonMsg, GoodsTransactionInfo goodsTransaction) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {
			assembleSuccessXml(builder, goodsTransaction.getFailedCode(),
					goodsTransaction.getFailedReason(),
					goodsTransaction.getResMsg());
			if (goodsTransaction != null) {
				builder.append("<ptOrderNo>");
				if (StringUtils.isNotEmpty(goodsTransaction.getPtOrderNo())) {
					builder.append(goodsTransaction.getPtOrderNo());
				}
				builder.append("</ptOrderNo>");
				builder.append("<status>");
				if (StringUtils.isNotEmpty(goodsTransaction.getStatus())) {
					builder.append(goodsTransaction.getStatus());
				}
				builder.append("</status>");
				builder.append("<supOrderNo>");
				if (StringUtils.isNotEmpty(goodsTransaction.getSupOrderNo())) {
					builder.append(goodsTransaction.getSupOrderNo());
				}
				builder.append("</supOrderNo>");
				builder.append("<supOrderSuccessTime>");
				if (StringUtils.isNotEmpty(goodsTransaction
						.getSupOrderSuccessTime())) {
					builder.append(goodsTransaction.getSupOrderSuccessTime());
				}
				builder.append("</supOrderSuccessTime>");
			}
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 组织商品同步的返回xml数据
	 * 
	 * @param resCode
	 *            响应状态码
	 * @param resReasonMsg
	 *            响应信息
	 * @param goods
	 *            商品列表
	 * @return
	 */
	public static String assembleXmlForGoodsSync(String resCode,
			String resReasonMsg, List<Goods> goods) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {
			if (goods != null && goods.size() > 0 && goods.get(0) != null) {
				Goods g = goods.get(0);
				assembleSuccessXml(builder, g.getFailedCode(),
						g.getFailedReason(), "SUCCESS");
				for (Goods good : goods) {
					String goodsName = good.getGoodsName();
					String descrip = good.getGoodsDescription();
					builder.append("<goods>");
					builder.append("<goodsId>");
					if (StringUtils.isNotEmpty(good.getGoodsId())) {
						builder.append(good.getGoodsId());
					}
					builder.append("</goodsId>");
					builder.append("<brandId>");
					if (StringUtils.isNotEmpty(good.getGoodsCategoryId())) {
						builder.append(good.getGoodsCategoryId());
					}else
					{
						builder.append(good.getBrandId());
					}
					builder.append("</brandId>");
					builder.append("<goodsName>");
					if (StringUtils.isNotEmpty(goodsName)) {
						goodsName = StringFilter.filterAngleBrackets(goodsName);
						builder.append(goodsName);
					}
					builder.append("</goodsName>");
					builder.append("<price>");
					if (StringUtils.isNotEmpty(good.getCommonSalePrice())&&!good.getCommonSalePrice().equals("0")) {

						String commonSalePrice = good.getCommonSalePrice();
						commonSalePrice = DataDeal
								.converIntegerToString(commonSalePrice);
						builder.append(commonSalePrice);
					}else
					{
						builder.append(DataDeal
								.converIntegerToString(good.getInPrice()));
					}
					builder.append("</price>");
					builder.append("<parValue>");
					if (StringUtils.isNotEmpty(good.getGoodsMoney())) {
						String goodsMoney = good.getGoodsMoney();
						goodsMoney = DataDeal.converIntegerToString(goodsMoney);
						builder.append(goodsMoney);
					}
					builder.append("</parValue>");
					builder.append("<rechargeMode>");
					if (StringUtils.isNotEmpty(good.getRechargeMode())) {
						builder.append(good.getRechargeMode());
					}
					builder.append("</rechargeMode>");
					builder.append("<description>");
					if (StringUtils.isNotEmpty(descrip)) {
						descrip = StringFilter.filterAngleBrackets(descrip);
						builder.append(descrip);
					}
					builder.append("</description>");
					builder.append("</goods>");
				}
			}
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 组织商品详细信息查询时的xml数据
	 * 
	 * @param resCode
	 *            响应状态码
	 * @param resReasonMsg
	 *            响应信息
	 * @param goods
	 *            商品信息
	 * @return
	 */
	public static String assembleXmlForGoodsDetailQuery(String resCode,
			String resReasonMsg, Goods goods) {
		String[] accountTypeNames = getAccountTypeNames(goods.getAccountType());
		String[] gameAreaNames = getGameAreaNames(goods.getGameArea());
		List<AreaServer> areaList = getGameAreas(goods.getGameArea2());
		List<AreaServer> areaSerList = getAreaServer(goods.getGameServer());
		List<ChargeTypeInfo> chargeList = getChargeTpye(goods.getChargeType());
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {
			assembleSuccessXml(builder, goods.getFailedCode(),
					goods.getFailedReason(), goods.getResMsg());
			if (goods != null) {
				String goodsName = goods.getGoodsName();
				builder.append("<goodsId>");
				if (StringUtils.isNotEmpty(goods.getGoodsId())) {
					builder.append(goods.getGoodsId());
				}
				builder.append("</goodsId>");
				builder.append("<goodsName>");
				if (StringUtils.isNotEmpty(goodsName)) {
					goodsName = StringFilter.filterAngleBrackets(goodsName);
					builder.append(goodsName);
				}
				builder.append("</goodsName>");
				builder.append("<brandId>");
				if (StringUtils.isNotEmpty(goods.getGoodsCategoryId())) {
					builder.append(goods.getGoodsCategoryId());
				}
				builder.append("</brandId>");
				builder.append("<gameUnit>");
				if (StringUtils.isNotEmpty(goods.getGameUnit())) {
					builder.append(goods.getGameUnit());
				}
				builder.append("</gameUnit>");

				builder.append("<noteinfo>");
				if (StringUtils.isNotEmpty(goods.getNoteinfo())) {
					builder.append(goods.getNoteinfo());
				}
				builder.append("</noteinfo>");
				if (accountTypeNames != null && accountTypeNames.length > 0) {
					assembleAccountType(accountTypeNames, builder);
				}
				if (chargeList != null && !chargeList.isEmpty()) {
					assembleChargeType(chargeList, builder);
				}
				if (gameAreaNames != null && gameAreaNames.length > 0) {
					assembleAreaServer(gameAreaNames, areaSerList, builder);
				}
				if (areaList != null && !areaList.isEmpty()) {
					assembleAreaServer(areaList, builder);
				}
			}
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 组织提卡的xml数据
	 * 
	 * @param resCode
	 * @param resReasonMsg
	 * @param cardList
	 * @return
	 */
	public static String assembleXmlForGetCard(String resCode,
			String resReasonMsg, CardInfo cardInfo, String ptOrderNo) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {

			String cardid = cardInfo.getCardid();
			String cardname = cardInfo.getCardname();
			String cardnum = cardInfo.getCardnum();
			String cardNoPwdExptime = cardInfo.getCardNoPwdExptime();
			String supOrderNo = cardInfo.getSupOrderNo();
			String failedCode = cardInfo.getFailedCode();
			String failedReason = cardInfo.getFailedReason();

			if (cardNoPwdExptime != null && !("".equals(cardNoPwdExptime))) {
				builder.append("<resMsg>");
				builder.append("SUCCESS");
				builder.append("</resMsg>");
				builder.append("<ptOrderNo>");
				builder.append(ptOrderNo);
				builder.append("</ptOrderNo>");
				if (StringUtils.isNotEmpty(cardid)) {
					builder.append("<cardId>");
					builder.append(cardid);
					builder.append("</cardId>");
				}
				builder.append("<cardNum>");
				builder.append(cardnum);
				builder.append("</cardNum>");
				builder.append("<cardName>");
				builder.append(cardname);
				builder.append("</cardName>");
				builder.append("<supOrderNo>");
				builder.append(supOrderNo);
				builder.append("</supOrderNo>");
				builder.append("<cards>");

				String[] strArr = cardNoPwdExptime.split(";");
				for (int i = 0; i < strArr.length; i++) {
					builder.append("<card>");
					String card = strArr[i];
					if (card != null && !("".equals(card))) {
						String[] cardArr = card.split(",");
						String cardNo = cardArr[0];
						String cardPws = cardArr[1];
						String expireTime = "";
						if (cardArr.length > 2) {
							expireTime = cardArr[2];
						}
						builder.append("<cardNo>");
						builder.append(cardNo);
						builder.append("</cardNo>");
						builder.append("<cardPws>");
						builder.append(cardPws);
						builder.append("</cardPws>");
						if (StringUtils.isNotEmpty(expireTime)) {
							builder.append("<expireTime>");
							builder.append(expireTime);
							builder.append("</expireTime>");
						}
					}
					builder.append("</card>");
				}
				builder.append("</cards>");
			} else {
				if (failedCode != null && !("".equals(failedCode))) {
					builder.append("<resMsg>");
					builder.append("FAILED");
					builder.append("</resMsg>");
					builder.append("<failedCode>");
					builder.append(failedCode);
					builder.append("</failedCode>");
					builder.append("<failedReason>");
					builder.append(failedReason);
					builder.append("</failedReason>");
				} else {
					builder.append("<resMsg>");
					builder.append("FAILED");
					builder.append("</resMsg>");
					builder.append("<failedCode>");
					builder.append("207");
					builder.append("</failedCode>");
					builder.append("<failedReason>");
					builder.append("商品库存不足");
					builder.append("</failedReason>");
					builder.append("<ptOrderNo>");
					builder.append(ptOrderNo);
					builder.append("</ptOrderNo>");
				}
			}
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 订单查询返回信息
	 * 
	 * @param resCode
	 * @param resReasonMsg
	 * @param ptOrderNo
	 * @param order
	 * @return
	 */
	public static String assembleXmlForOrderQuery(String resCode,
			String resReasonMsg, OrderInfo orderInfo) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {
			assembleSuccessXml(builder, orderInfo.getFailedCode(),
					orderInfo.getFailedReason(), orderInfo.getResMsg());
			builder.append("<ptOrderNo>");
			if (StringUtils.isNotEmpty(orderInfo.getPtOrderNo())) {
				builder.append(orderInfo.getPtOrderNo());
			}
			builder.append("</ptOrderNo>");
			builder.append("<supOrderNo>");
			if (StringUtils.isNotEmpty(orderInfo.getSupOrderNo())) {
				builder.append(orderInfo.getSupOrderNo());
			}
			builder.append("</supOrderNo>");
			builder.append("<status>");
			if (StringUtils.isNotEmpty(orderInfo.getStatus())) {
				builder.append(orderInfo.getStatus());
			}
			builder.append("</status>");
		} else {
			assembleFailXml(resCode, resReasonMsg, builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 组织对账文件获取接口的xml数据
	 * 
	 * @param resCode
	 * @param resMsg
	 * @param urlInfo
	 * @return
	 */
	public static String assembleXmlForAccountChecking(List<Bill> billList,
			String resCode, String resMsg) {
		StringBuilder builder = new StringBuilder();
		builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		builder.append("<response>");
		if (Constant.SUCCESS.equals(resCode)) {

			if (billList != null && !billList.isEmpty()) {
				assembleSuccessXml(builder, "", "", "SUCCESS");
				builder.append("<bills>");
				for (Bill bill : billList) {
					builder.append("<orderBill>");
					builder.append("<ptOrderNo>");
					if (StringUtils.isNotEmpty(bill.getMerchantOrderId())) {
						builder.append(bill.getMerchantOrderId());
					}
					builder.append("</ptOrderNo>");
					builder.append("<gameAccount>");
					if (StringUtils.isNotEmpty(bill.getGameAccount())) {
						builder.append(bill.getGameAccount());
					}
					builder.append("</gameAccount>");
					builder.append("<goodsId>");
					if (StringUtils.isNotEmpty(bill.getGoodsId())) {
						builder.append(bill.getGoodsId());
					}
					builder.append("</goodsId>");
					builder.append("<unitPrice>");
					int goodsSalePrice = bill.getGoodsSalePrice();
					// if (StringUtils.isNotEmpty(bill.getUnitPrice())) {
					// builder.append(bill.getUnitPrice());
					// }
					builder.append(DataDeal.converIntegerToString(String
							.valueOf(goodsSalePrice)));
					builder.append("</unitPrice>");
					builder.append("<buyNum>");
					// if (StringUtils.isNotEmpty(bill.getBuyNum())) {
					// builder.append(bill.getBuyNum());
					// }
					builder.append(bill.getBuyNum());
					builder.append("</buyNum>");
					builder.append("<totalPrice>");
					int totalPrice = bill.getTotalPrice();
					// if (StringUtils.isNotEmpty(bill.getTotalPrice())) {
					// builder.append(bill.getTotalPrice());
					// }
					builder.append(DataDeal.converIntegerToString(String
							.valueOf(totalPrice)));
					builder.append("</totalPrice>");
					builder.append("<status>");
					if (StringUtils.isNotEmpty(bill.getStatus())) {
						// 订单状态 0：失败 1：成功 2：处理中 3：存疑
						String status = bill.getStatus();
						if ("0".equals(status)) {
							builder.append("ORDER_FAILED");
						} else if ("1".equals(status)) {
							builder.append("ORDER_SUCCESS");
						} else if ("2".equals(status)) {
							builder.append("ORDER_UNDERWAY");
						} else if ("3".equals(status)) {
							builder.append("ORDER_DUBIOUS");
						}
					}
					builder.append("</status>");
					builder.append("</orderBill>");
				}
				builder.append("</bills>");

			} else {
				assembleSuccessXml(builder, "", "", "SUCCESS");
				builder.append("<bills>");
				builder.append("<orderBill>");
				builder.append("<ptOrderNo>");
				builder.append("</ptOrderNo>");
				builder.append("<gameAccount>");
				builder.append("</gameAccount>");
				builder.append("<goodsId>");
				builder.append("</goodsId>");
				builder.append("<unitPrice>");
				builder.append("</unitPrice>");
				builder.append("<buyNum>");
				builder.append("</buyNum>");
				builder.append("<totalPrice>");
				builder.append("</totalPrice>");
				builder.append("<status>");
				builder.append("</status>");
				builder.append("</orderBill>");
				builder.append("</bills>");
			}

		} else {
			assembleFailXml(ExCodeDes.UNKNOW_ERROR.getCode(),
					ExCodeDes.UNKNOW_ERROR.getDescription(), builder);
		}
		builder.append("</response>");
		xmlData = builder.toString();
		return xmlData;
	}

	/**
	 * 循环card信息
	 * 
	 * @param cardList
	 * @param builder
	 */
	@SuppressWarnings("unused")
	private static void loopCards(List<CardInfo> cardList, StringBuilder builder) {
		builder.append("<cards>");
		for (CardInfo card : cardList) {
			builder.append("<card>");
			builder.append("<cardNo>");
			if (StringUtils.isNotEmpty(card.getCardNo())) {
				builder.append(card.getCardNo());
			}
			builder.append("</cardNo>");
			builder.append("<cardPws>");
			if (StringUtils.isNotEmpty(card.getCardPws())) {
				builder.append(card.getCardPws());
			}
			builder.append("</cardPws>");
			builder.append("<expireTime>");
			if (StringUtils.isNotEmpty(card.getExpireTime())) {
				builder.append(card.getExpireTime());
			}
			builder.append("</expireTime>");
			builder.append("</card>");
		}
		builder.append("</cards>");
	}

	/**
	 * 返回成功时的xml头数据
	 * 
	 * @param builder
	 */
	private static void assembleSuccessXml(StringBuilder builder,
			String failedCod, String failedReason, String resMsg) {
		builder.append("<resMsg>");
		if (StringUtils.isNotEmpty(resMsg)) {
			builder.append(resMsg);
		}
		builder.append("</resMsg>");
		builder.append("<failedCode>");
		if (StringUtils.isNotEmpty(failedCod)) {
			builder.append(failedCod);
		}
		builder.append("</failedCode>");
		builder.append("<failedReason>");
		if (StringUtils.isNotEmpty(failedReason)) {
			builder.append(failedReason);
		}
		builder.append("</failedReason>");
	}

	/**
	 * 返回失败时的xml数据
	 * 
	 * @param resCode
	 * @param resReasonMsg
	 * @param builder
	 */
	private static void assembleFailXml(String resCode, String resReasonMsg,
			StringBuilder builder) {
		builder.append("<resMsg>SUCCESS</resMsg>");
		builder.append("<failedCode>");
		builder.append(resCode);
		builder.append("</failedCode>");
		builder.append("<failedReason>");
		builder.append(resReasonMsg);
		builder.append("</failedReason>");
	}

	/**
	 * 组织账户信息xml
	 * 
	 * @param accountTypeNames
	 * @param builder
	 */
	private static void assembleAccountType(String[] accountTypeNames,
			StringBuilder builder) {
		if (accountTypeNames != null && accountTypeNames.length > 0) {
			builder.append("<accountType_s>");
			for (String accountTypeName : accountTypeNames) {
				builder.append("<accountType>");
				builder.append("<accountTypeName>");
				if (StringUtils.isNotEmpty(accountTypeName)) {
					accountTypeName = StringFilter
							.filterAngleBrackets(accountTypeName);
					builder.append(accountTypeName);
				}
				builder.append("</accountTypeName>");
				builder.append("</accountType>");
			}
			builder.append("</accountType_s>");
		}
	}

	/**
	 * 组织ChargeType信息xml
	 * 
	 * @param chargeList
	 * @param builder
	 */
	private static void assembleChargeType(List<ChargeTypeInfo> chargeList,
			StringBuilder builder) {
		if (chargeList != null && chargeList.size() > 0) {
			builder.append("<chargeTypes>");
			for (ChargeTypeInfo charge : chargeList) {
				builder.append("<chargeType>");
				if (charge != null) {
					String typeName = charge.getChargetypeName();
					String buyNumName = charge.getTbuynumbername();
					builder.append("<chargeTypeName>");
					if (StringUtils.isNotEmpty(typeName)) {
						typeName = StringFilter.filterAngleBrackets(typeName);
						builder.append(charge.getChargetypeName());
					}
					builder.append("</chargeTypeName>");
					builder.append("<buyList>");
					if (StringUtils.isNotEmpty(charge.getBuyList())) {
						builder.append(charge.getBuyList());
					}
					builder.append("</buyList>");
					builder.append("<buyListPoint>");
					if (StringUtils.isNotEmpty(charge.getTbuynumber_list())) {
						builder.append(charge.getTbuynumber_list());
					}
					builder.append("</buyListPoint>");
					builder.append("<buyListPointName>");
					if (StringUtils.isNotEmpty(buyNumName)) {
						buyNumName = StringFilter
								.filterAngleBrackets(buyNumName);
						builder.append(buyNumName);
					}
					builder.append("</buyListPointName>");
				}
				builder.append("</chargeType>");
			}
			builder.append("</chargeTypes>");
		}
	}

	/**
	 * 组织AreaServer信息xml
	 * 
	 * @param gameAreaNames
	 * @param areaSerList
	 * @param builder
	 */
	private static void assembleAreaServer(String[] gameAreaNames,
			List<AreaServer> areaSerList, StringBuilder builder) {
		if (gameAreaNames != null && gameAreaNames.length > 0) {
			builder.append("<gameAreas>");
			for (String areaName : gameAreaNames) {
				builder.append("<gameArea>");
				builder.append("<gameAreaName>");
				if (StringUtils.isNotEmpty(areaName)) {
					areaName = StringFilter.filterAngleBrackets(areaName);
					builder.append(areaName);
				}
				builder.append("</gameAreaName>");
				if (areaSerList != null && areaSerList.size() > 0) {
					builder.append("<gameServers>");
					for (AreaServer as : areaSerList) {
						String gameAreaName = as.getGameAreaName();
						if (StringUtils.isNotEmpty(gameAreaName)) {
							gameAreaName = StringFilter
									.filterAngleBrackets(gameAreaName);
						}

						String serName = as.getGamesrvName();
						if (areaName.equals(gameAreaName)) {
							if (StringUtils.isNotEmpty(serName)) {
								builder.append("<gameServer>");
								builder.append("<gameServerName>");
								builder.append(serName);
								builder.append("</gameServerName>");
								builder.append("</gameServer>");
							}
						}
					}
					builder.append("</gameServers>");
				}
				builder.append("</gameArea>");
			}
			builder.append("</gameAreas>");
		}
	}

	private static void assembleAreaServer(List<AreaServer> areaSerList,
			StringBuilder builder) {
		builder.append("<gameAreas>");
		for (AreaServer as : areaSerList) {
			builder.append("<gameArea>");
			builder.append("<gameAreaName>");
			builder.append(as.getGameAreaName());
			builder.append("</gameAreaName>");
			builder.append("<gameAreaCode >");
			builder.append(as.getGameAreaCode());
			builder.append("</gameAreaCode >");
			builder.append("</gameArea>");
		}
		builder.append("</gameAreas>");
	}

	private static String[] getAccountTypeNames(String acctountTypeStr) {
		String[] accountTypeNames = null;
		if (StringUtils.isNotEmpty(acctountTypeStr)) {
			accountTypeNames = acctountTypeStr.split("&&");
		}
		return accountTypeNames;
	}

	private static String[] getGameAreaNames(String gameAreaStr) {
		String[] gameAreas = null;
		if (StringUtils.isNotEmpty(gameAreaStr)) {
			gameAreas = gameAreaStr.split("&&");
		}
		return gameAreas;
	}

	private static List<AreaServer> getGameAreas(String gameAreaStr) {
		List<AreaServer> list = new ArrayList<AreaServer>();
		if (StringUtils.isNotEmpty(gameAreaStr)) {
			String[] areas = gameAreaStr.split("&&");
			if (areas != null && areas.length > 0) {
				for (String area : areas) {
					AreaServer as = new AreaServer();
					String[] areaNameAndCode = area.split("=");
					if (areaNameAndCode != null && areaNameAndCode.length > 1) {
						as.setGameAreaName(areaNameAndCode[0]);
						as.setGameAreaCode(areaNameAndCode[1]);
						list.add(as);
					}
				}
			}
		}

		return list;
	}

	private static List<AreaServer> getAreaServer(String areaServerStr) {
		List<AreaServer> list = new ArrayList<AreaServer>();
		if (StringUtils.isNotEmpty(areaServerStr)) {
			String[] areaServers = areaServerStr.split("&&");
			if (areaServers != null && areaServers.length > 0) {
				for (String areaSer : areaServers) {
					AreaServer as = new AreaServer();
					if (StringUtils.isNotEmpty(areaSer)) {
						String[] areaSers = areaSer.split("##");
						if (areaSers != null) {
							if (areaSers.length >= 1
									&& !"null".equals(areaSers[0])) {
								as.setGameAreaName(areaSers[0]);
							}
							if (areaSers.length >= 2
									&& !"null".equals(areaSers[1])) {
								as.setGamesrvName(areaSers[1]);
							}
							list.add(as);
						}
					}
				}
			}
		}
		return list;
	}

	private static List<ChargeTypeInfo> getChargeTpye(String chargeTypeStr) {
		List<ChargeTypeInfo> list = new ArrayList<ChargeTypeInfo>();
		if (StringUtils.isNotEmpty(chargeTypeStr)) {
			String[] chargeTypes = chargeTypeStr.split("&&");
			if (chargeTypes != null && chargeTypes.length > 0) {
				for (String chargeType : chargeTypes) {
					ChargeTypeInfo chargeInfo = new ChargeTypeInfo();
					if (StringUtils.isNotEmpty(chargeType)) {
						String[] chargeTs = chargeType.split("##");
						if (chargeTs != null) {
							if (chargeTs.length >= 1
									&& !"null".equals(chargeTs[0])) {
								chargeInfo.setChargetypeName(chargeTs[0]);
							}
							if (chargeTs.length >= 2
									&& !"null".equals(chargeTs[1])) {
								chargeInfo.setBuyList(chargeTs[1]);
							}
							if (chargeTs.length >= 3
									&& !"null".equals(chargeTs[2])) {
								chargeInfo.setTbuynumber_list(chargeTs[2]);
							}
							if (chargeTs.length >= 4
									&& !"null".equals(chargeTs[3])) {
								chargeInfo.setTbuynumbername(chargeTs[3]);
							}
							list.add(chargeInfo);
						}
					}
				}
			}
		}
		return list;
	}

}
